<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>



<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<meta charset="utf-8" />
<title>青麦门店系统|商品定价</title>
<meta
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
	name="viewport" />
<meta content="" name="description" />
<meta content="" name="author" />

<!-- ================== BEGIN BASE CSS STYLE ================== -->
<%@ include file="../include/inc_head.jsp"%>
<!-- ================== END BASE CSS STYLE ================== -->

<!-- ================== BEGIN BASE JS ================== -->
<script src="/assets/plugins/pace/pace.min.js"></script>
<link href="/assets/plugins/bootstrap-datepicker/css/datepicker3.css" rel="stylesheet" />
<!-- ================== END BASE JS ================== -->
</head>
<body>
	<!-- begin #page-loader -->
	<div id="page-loader" class="fade in">
		<span class="spinner"></span>
	</div>
	<!-- end #page-loader -->

	<!-- begin #page-container -->
	<div id="page-container"
		class="fade page-sidebar-fixed page-header-fixed">
		<!-- begin #header -->
		<%@ include file="../include/inc_header.jsp"%>
		<!-- end #header -->

		<!-- begin #sidebar -->
		<%@ include file="../include/inc_left.jsp"%>
		<!-- end #sidebar -->

		<!-- begin #content -->
		<div id="content" class="content">
			<!-- begin breadcrumb -->
			<ol class="breadcrumb pull-right">
				<li><a href="javascript:;">首页</a></li>
				<li class="active">商品调价</li>
			</ol>
			<!-- end breadcrumb -->
			<!-- begin page-header -->
			<h1 class="page-header">商品调价</h1>
			<!-- end page-header -->

	<div class="panel panel-inverse">
				<div class="panel-heading">

					<h4 class="panel-title" style="color:#ffffff;">查询条件</h4>
				</div>
				<div class="panel-body">
					<form id="search-form" class="form-inline" action="/product/getProdSsuPriceList" method="POST">
								<!-- <div class="switch" data-on="success" data-off="warning">
								    <input type="checkbox" checked />
								</div> -->
								<div class="form-group m-r-10">
									<input type="text" class="form-control" name="skuName" placeholder="商品名称" />
								</div>
								<div class="form-group m-r-10">
									 <select class="form-control" name="isOnline">
									 		<option value="-1">商品状态</option>
											<option value="true">上架</option>
											<option value="false">下架</option>
                                        </select>
								</div>
								<div class="form-group m-r-10">
									 <select class="form-control" name="channel">
									 		<option value="-1">渠道</option>
											<option value="1">B端</option>
											<option value="2">C端</option>
                                        </select>
								</div>
								<div class="form-group m-r-10">
									<input type="text" class="form-control" readonly="readonly" name="startDate" id="startDate" placeholder="日期开始" />
                                      - <input type="text" class="form-control" readonly="readonly" name="endDate" id="endDate" placeholder="日期结束" />
								</div>
								<button type="button" class="btn btn-sm btn-warning m-r-5" onclick="doSearch();">查询</button>
								<button type="button" class="btn btn-sm btn-primary m-r-5" >导出</button>
							</form>
					
				</div>
			</div>
			<div class="panel panel-inverse">
				<div class="panel-body">
					<table id="data-table" class="table table-striped table-bordered"
					data-options="iconCls: 'icon-edit',
					    singleSelect: true,
					    toolbar: '#tb'">
						<tr>
						</tr>
					</table>
					<div id="tb" style="height:auto;padding-bottom:5px;padding-left:25px;">
					  <a href="javascript:void(0);" type="button" onclick="batchUpShelf()" id="batchUp" class="btn btn-sm btn-success m-r-5" >批量上架</a>
					   <a href="javascript:void(0);" type="button" onclick="batchDownShelf()" id="batchDown" class="btn btn-sm btn-danger m-r-5" >批量下架</a>
				 	</div>
				</div>
			</div>
			
			<!-- 模态框（Modal） -->
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog" style="width:1000px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h4 class="modal-title" id="myModalLabel">
							编辑商品
						</h4>
					</div>
					<div class="modal-body">
						<form id="editForm" class="form-inline" action="/product/modifyPrice" method="POST">
							
							<input type="hidden" class="form-control" id="id" name="id" />
							<!-- <input type="hidden" class="form-control" id="uT" name="uT" /> -->
							
							<div class="form-group m-r-10">
								<label class="control-label">sku名称:</label>
								<input type="text" class="form-control" readonly="disabled" id="skuName" />
							</div>
							
							<div class="form-group m-r-10">
								<label class="control-label">ssu名称:</label>
								<input type="text" class="form-control" readonly="disabled" id="ssuName" />
							</div>
							
							<div class="form-group">
							    <label class="control-label">价格:</label>
								<input type="text" class="form-control" id="price" name="price" />
							</div>
							
							
							
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭
						</button>
						<button id="modifyPrice" type="button" class="btn btn-primary">
							提交更改
						</button>
					</div>
				</div><!-- /.modal-content -->
			</div><!-- /.modal -->

		</div>
		<!-- end #content -->

		<%@ include file="../include/inc_footer.jsp"%>
		<!-- begin scroll to top btn -->
		<a href="javascript:;"
			class="btn btn-icon btn-circle btn-success btn-scroll-to-top fade"
			data-click="scroll-top"><i class="fa fa-angle-up"></i></a>
		<!-- end scroll to top btn -->
	</div>
	<!-- end page container -->

	<!-- ================== BEGIN BASE JS ================== -->
	<%@ include file="../include/inc_foot.jsp"%>

	<!-- ================== END BASE JS ================== -->

	<!-- ================== BEGIN PAGE LEVEL JS ================== -->
	<script src="/assets/plugins/DataTables/media/js/jquery.dataTables.js"></script>
	<script src="/assets/plugins/DataTables/media/js/dataTables.bootstrap.min.js"></script>
	<script src="/assets/js/table-manage-default.demo.min.js"></script>
	<script src="/assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
	<script src="/assets/plugins/bootstrap-datepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
	<script src="/assets/js/apps.min.js"></script>
	
	
	
	<link rel="stylesheet" type="text/css" href="/assets/jQueryEasyui/themes/gray/easyui.css">  
<link rel="stylesheet" type="text/css" href="/assets/jQueryEasyui/themes/icon.css">  
<!-- <link rel="stylesheet" type="text/css" href="/assets/jQueryEasyui/style.css">  
<link rel="stylesheet" type="text/css"
	href="/assets/jQueryEasyui/demo.css">
	<link rel="stylesheet" type="text/css"
	href="/assets/jQueryEasyui/list.css"> -->
<!-- <script type="text/javascript" src="/assets/jQueryEasyui/jquery-1.8.0.min.js"></script>  --> 
<script type="text/javascript" src="/assets/jQueryEasyui/jquery.easyui.min.js"></script> 
<script type="text/javascript" src="/assets/jQueryEasyui/easyui-lang-zh_CN.js"></script> 

<link rel="stylesheet" type="text/css" href="/assets/plugins/bootstrap-switch/bootstrap-switch.css">  
<script type="text/javascript" src="/assets/plugins/bootstrap-switch/bootstrap-switch.js"></script>

	<script>
			$(function() {
		$('#data-table')
				.datagrid(
						{
							title : '商品调价',
							loadMsg : '数据加载中,请稍后................',
							nowrap : true,
							striped : true,
							url : '/product/getSsuPriceList',
							pagination : true,
							rownumbers : true,
							singleSelect : false,
							border : true,
							pageSize : '10',
							columns : [ [
									{
										field : 'check',
										checkbox : true
									},
									{
										field : 'productSsu',
										title : '售卖商品名称',
										width :  200,
										align : 'center',
										formatter : function(value, rec, index) {
											 if(value==null){  
											        return "";  
											    }else  
											        return rec.productSsu.ssuName;  
										}
									},
									{
										field : 'sku',
										title : '商品名称',
										width :  200,
										align : 'center',
										formatter : function(value, rec, index) {
											if(value==null){  
										        return "";  
										    }else  
										        return rec.sku.skuName; 
										}
									},
									{
										field : 'price',
										title : '价格',
										width :   170,
										align : 'center',
										formatter : function(value, rec, index) {
											if(value==null){  
										        return "";  
										    }else  
										        return value/1000; 
										}
									},
									{
										field : 'channel',
										title : '渠道',
										width :   80,
										align : 'center',
										formatter : function(value, rec, index) {
											if(value==1){  
										        return "B端";  
										    }
											if(value==2){
												return "C端"; 
											}
										        
										}
									},
									{
										field : 'uT',
										title : '最后修改时间',
										width :   170,
										align : 'center',
										formatter : function(value, rec, index) {
											if(value==null){  
										        return "";  
										    }else  
										        return new Date(parseInt(value) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
										}
									},
									
									{
										field : 'isOnline',
										title : '上下架',
										width :  170,
										align : 'center',
										formatter : function(value, rec, index) {
											var str="";
											if(value){
												str='<span class="btn-success">已上架</span>';
												//str="<input class='easyui-switchbutton' data-options='onText:'Yes',offText:'No''>"
											}else{
												str='<a href="javascript:void(0);" class="btn-danger">已下架</a>';
												//str=str="<input class='easyui-switchbutton' data-options='onText:'Yes',offText:'No''>"
											}
											return str;
										}
									},
									
									
									{
										field : 'tttt',
										title : '操作',
										width :  150,
										align : 'center',
										formatter : function(value, rec, index) {
											var str ="<a type='buttom' class='btn btn-sm btn-warning m-r-5' onclick='editRow("+JSON.stringify(rec)+")'>编辑</a>";
											if(rec.isOnline){
												str+="<a href='javascript:void(0);' onclick='downShelf("+JSON.stringify(rec)+",this)'  class='btn btn-sm btn-danger'>下架</a>"
											}else{
												str+="<a href='javascript:void(0);' onclick='upShelf("+JSON.stringify(rec)+",this)' class='btn btn-sm btn-success'>上架</a>"
											}
											//rec.isOnline=true;
											return str;
										}
									} ] ]
						});
	 var p = $('#data-table').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,
			pageList : [ 10, 20, 30 ]
		});  

		//获取活动分类
	});
			
	//修改价格
	$("#modifyPrice").click(function() {
	$("input[name='price']").val($("input[name='price']").val()*1000);
    var params = $("#editForm").serialize();
    var params2 = $("#editForm").serializeArray();
    console.log(params);  //name=zhangsan&sex=1&age=20
    console.log(params2);  //[Object, Object, Object]
    $.param(params); 
    $.ajax( {
        type : "POST",
        url : "${ctx}/product/modifyPrice",
        data : params,
        success : function(data) {
        	console.log("----------------");
        	console.log(data);
            if(data.code=="1"){
            	console.log("---修改价格成功---")
            	$("#myModal").modal('hide');
            	$('#data-table').datagrid('reload');
            }
        }
    });
   })
	
	//查询
	function doSearch() {
		var formData = $("#search-form").serializeArray();
		console.log(formData);
		console.log($("#search-form").serializeArray()[1].value);
		
		$('#data-table').datagrid('reload', {
			skuName : formData[0].value,
			isOnline : formData[1].value,
			channel:formData[2].value,
			startDate : formData[3].value,
			endDate : formData[4].value
		});
	}
	//修改操作
	function editRow(o) {
    	console.log(o);
    	var row = o;
        
		//alert('You click like action, row: ' + JSON.stringify(row));
		//console.log(row);
        $("#myModal").modal('show');
        $('#id').val(row.id);
        $('#skuName').val(row.sku.skuName);
        $('#ssuName').val(row.productSsu.ssuName);
        $('#price').val(row.price/1000);
        $('#questiontypename').val(row.questiontypename);

    }
    
  //模态增加
    function openAddModal() {
        $("#myModal").modal('show');
        $('#sid').val(null);
        $('#questiontype').val(null);
        $('#questiontypename').val(null);
    }
  
  	//上架
    function upShelf(o1,o2){
		console.log(o1);
    	var row = o1;
    	var that = o2;
    	console.log(that);
    	var array = [row]
    	console.log(array);
        //修改操作
		//alert('You click like action, row: ' + JSON.stringify(row));
		//console.log(row);
        //$("#myModal").modal('show');
        $('#skuId').val(row.id);
        $('#skuName').val(row.skuName);
        //调用导入sku接口
        $.ajax({
        	type : "POST",
            url : "${ctx}/product/batchOnline",
            data : JSON.stringify(array),
            dataType: "json",
            contentType:"application/json", 
            success : function(data) {
            	console.log("----------------");
            	console.log(data);
                if(data.code=="1"){
                	console.log("---上架成功---")
                	$("#myModal").modal('hide');
                	$('#data-table').datagrid('reload');
                }
            },
            complete:function(){
                //请求完成的处理
            },
            error:function(){
                //请求出错处理
            }
        });
	}
  	//批量上架
    function batchUpShelf(){
    	var selections= $('#data-table').datagrid('getSelections');
    	console.log("------------------");
    	console.log(selections);
        //修改操作
		//alert('You click like action, row: ' + JSON.stringify(row));
		//console.log(row);
        //$("#myModal").modal('show');
        //$('#skuId').val(row.id);
        //$('#skuName').val(row.skuName);
        //调用导入sku接口
        $.ajax({
        	type : "POST",
            url : "${ctx}/product/batchOnline",
            data : JSON.stringify(selections),
            dataType: "json",
            contentType:"application/json", 
            success : function(data) {
            	console.log("----------------");
            	console.log(selections);
                if(data.code=="1"){
                	console.log("---批量上架成功---")
                	$("#myModal").modal('hide');
                	$('#data-table').datagrid('reload');
                }
            },
            complete:function(){
                //请求完成的处理
            },
            error:function(){
                //请求出错处理
            }
        });
	}
  	//下架
    function downShelf(o1,o2){
		console.log(o1);
    	var row = o1;
    	var that = o2;
    	var array = [row]
    	console.log(array);
    	//console.log(that);
        //修改操作
		//alert('You click like action, row: ' + JSON.stringify(row));
		//console.log(row);
        //$("#myModal").modal('show');
        $('#skuId').val(row.id);
       
        $('#skuName').val(row.skuName);
        //调用导入sku接口
        $.ajax({
        	type : "POST",
            url : "${ctx}/product/batchOffline",
            data : JSON.stringify(array),
            dataType: "json",
            contentType:"application/json", 
            success : function(data) {
            	console.log("----------------");
            	console.log(data);
                if(data.code=="1"){
                	console.log("---下架成功---")
                	$("#myModal").modal('hide');
                	$('#data-table').datagrid('reload');
                }
            },
            complete:function(){
                //请求完成的处理
            },
            error:function(){
                //请求出错处理
            }
        });
	}
  	//批量下架
    function batchDownShelf(){
    	var selections= $('#data-table').datagrid('getSelections');
    	console.log("------------------");
    	console.log(selections);
        //调用导入sku接口
    	$.ajax({
        	type : "POST",
            url : "${ctx}/product/batchOffline",
            data : JSON.stringify(selections),
            dataType: "json",
            contentType:"application/json", 
            success : function(data) {
            	console.log("----------------");
            	console.log(selections);
                if(data.code=="1"){
                	console.log("---批量下架成功---")
                	$("#myModal").modal('hide');
                	$('#data-table').datagrid('reload');
                }
            },
            complete:function(){
                //请求完成的处理
            },
            error:function(){
                //请求出错处理
            }
        });
	}
	</script>
		<script>
		$(document).ready(function() {
			$("#startDate").datepicker({
		        format: 'yyyy-mm-dd',
		        language: "zh-CN",
		        keyboardNavigation: false,
		        forceParse: false,
		        calendarWeeks: false,
		        autoclose: true,
		    });
			$("#endDate").datepicker({
		        format: 'yyyy-mm-dd',
		        language: "zh-CN",
		        keyboardNavigation: false,
		        forceParse: false,
		        calendarWeeks: false,
		        autoclose: true,
		    });
			$("#startDate").on("changeDate",
		    function(e) {
		        $("#endDate").data("datepicker").setStartDate(e.date)
		    });
		    $("#endDate").on("changeDate",
		    function(e) {
		        $("#startDate").data("datepicker").setEndDate(e.date)
		    });

		}); 
		App.init();
	</script>

</body>
</html>